home *** CD-ROM | disk | FTP | other *** search
- unit Retry;
-
- interface
-
- uses Classes, DsgnIntf, SysUtils, ExtCtrls, Forms, Dialogs, Controls
- , PasUtils
- , ErrorMsg;
-
- type
-
- {------------------------------------------------------------------------------}
- { TInterval }
- {------------------------------------------------------------------------------}
-
- TInterval = class(TPersistent)
- private
- fInterval:Longint;
- fRandom:Longint;
- fProcessMessages: Boolean;
- fOnWaitOver: TNotifyEvent;
- protected
- procedure TimerEvent(Sender: TObject);
- procedure DoWaitOver(Sender: TObject); {virtual;}
- public
- constructor Create;
- constructor CreateDelay(DelayMS:LongInt;WaitNow:Boolean);
- constructor CreateRandomDelay(ShortMS,LongMS:LongInt;WaitNow:Boolean);
- procedure Execute;
- published
- property Interval: LongInt read fInterval write fInterval;
- property RandomTime: LongInt read fRandom write fRandom;
- property ProcessMessages: Boolean read fProcessMessages write fProcessMessages default True;
- property OnWaitOver: TNotifyEvent read fOnWaitOver write fOnWaitOver;
- end;
-
- TIntervalProperty = class(TClassProperty)
- public
- function GetAttributes: TPropertyAttributes; Override;
- end;
-
- {------------------------------------------------------------------------------}
- { TRetry }
- {------------------------------------------------------------------------------}
-
- TRetryExceptionEvent =
- procedure(Sender:TObject;E:Exception;var Action:TExceptionReAction) of object;
-
- TRetry = class(TPersistent)
- private
- fAskFirst: Boolean; {should we ask to ok retries before retrying?}
- fAutoRetry: Boolean; {if true we will do fMaxRetries before giving up}
- fAllowRetry: Boolean; {if the retry mechanism gives up, the user can allow more tries}
- fMaxRetries: Integer; {number of retries allowed before asking for feedback}
- fInterval: TInterval;
- fOnAction: TNotifyEvent;
- fCanIgnore: Boolean; {can an exception be ignored?}
- fErrorAction: TExceptionReAction; {defaults to reAsk}
- fErrorDialog: TErrorDialog; {can use a linked in error dialog before ours but after event}
- fOnException: TRetryExceptionEvent;
- protected
- procedure RetryException(Sender:TObject;E:Exception;var Action:TExceptionReAction);
- public
- constructor Create;
- constructor CreateAction(Action:TNotifyEvent;Exception:TRetryExceptionEvent);
- destructor Destroy;
- procedure Retry(Action:TNotifyEvent;Exception:TRetryExceptionEvent);
- procedure RetryAction(Action:TNotifyEvent);
- procedure Execute;
- published
- property Interval: TInterval read fInterval write fInterval;
- property RetryAuto: Boolean read fAutoRetry write fAutoRetry default True;
- property RetryMax: Integer read FMaxRetries write FMaxRetries default 1;
- property RetryAllow: Boolean read fAllowRetry write fAllowRetry default True;
- property RetryAskFirst: Boolean read fAskFirst write fAskFirst default True;
- property CanIgnore: Boolean read fCanIgnore write fCanIgnore;
- property ErrorAction: TExceptionReAction read fErrorAction write fErrorAction;
- property ErrorDialog: TErrorDialog read fErrorDialog write fErrorDialog;
- property OnAction: TNotifyEvent read fOnAction write fOnAction;
- property OnException: TRetryExceptionEvent read fOnException write fOnException;
- end;
-
- TRetryProperty = class(TClassProperty)
- public
- function GetAttributes: TPropertyAttributes; Override;
- end;
-
- implementation
-
-